package apps.reading.spider;

import java.util.ArrayList;
import java.util.List;

import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.Parser;
import org.htmlparser.filters.TagNameFilter;
import org.htmlparser.tags.LinkTag;
import org.htmlparser.util.NodeList;

import apps.reading.ReadingSpider;
import apps.reading.WebSourceParser;
import apps.reading.db.WebSourceBean;
import core.tool.common.StringHelper;
import core.tool.htmlparser.HtmlparserUtil;

@ReadingSpider(sourceType="0", type="2", url = "http://www.cnblogs.com/aggsite/topdiggs/")
public class CnBolgs10DaysTop extends BaseReading implements WebSourceParser {

	public WebSourceBean getContent(WebSourceBean webSourceBean) {
		String content=HtmlparserUtil.getNodeStr(webSourceBean.getContentURL(), "div", "id", "cnblogs_post_body",true);
		webSourceBean.setContent(content);
		return webSourceBean;
	}

	public List<WebSourceBean> getWebSourceTitleList(String url) {
		return super.getWebSourceTitleList(url, "div", "class", "post_item_body");
	}

	WebSourceBean getWebSourceBeanOfStr(String result,String url) {
		WebSourceBean webSourceBean=new WebSourceBean();
		try {
			Parser parser = new Parser();
			parser.setInputHTML(result);
			NodeFilter filter = new TagNameFilter("A");
			NodeList nodelist = parser.parse(filter);
			for (int i = 0; i < nodelist.size(); i++) {
				Node node = nodelist.elementAt(i);
				LinkTag link = (LinkTag) nodelist.elementAt(i);
				if (i == 0) {
					webSourceBean.setContentURL(link.getAttribute("href"));
					webSourceBean.setTitle((link.getStringText()));
				}
				if (i == 1) {
					webSourceBean.setRemark(link.getStringText());
				}
				if (i == 2) {
					webSourceBean.setAuthor(link.getStringText());
				}				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return webSourceBean;
	}

}
